package com.leetcode.offer;

import com.leetcode.entity.TreeNode;

import java.util.Stack;

/**
 * @author zfl
 * @Classname MirrorTree
 * @Description 二叉树的镜像
 * 不太熟练
 * @Date 2020/10/17 20:06
 */
public class MirrorTree {

    public static TreeNode mirrorTree(TreeNode root) {
        if(root == null) {
            return null;
        }

        Stack<TreeNode> stack = new Stack<>();
        stack.add(root);
        while (!stack.isEmpty()) {
            TreeNode node = stack.pop();
            if(node.left != null) {
                stack.add(node.left);
            }
            if(node.right != null) {
                stack.add(node.right);
            }
            TreeNode tmp = node.left;
            node.left = node.right;
            node.right = tmp;
        }
        return root;

    }

}
